package com.school_admin.config;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Result <T>{
    private Integer code;
    private String msg;
    private T data;
    // 省略构造方法、getter和setter方法
    public static <T> Result<T> success() {
        return new Result<>(200,"成功",null);
    }

    public static <T> Result<T> success(T data) {
        return new Result<>(200,"成功",data);
    }

    public static <T> Result<T> success(T data, String message) {
        return new Result<>(200,message,data);
    }

    public static <T> Result<T> success(String message) {
        return new Result<>(200,message,null);
    }
    // 响应失败重载

    public static<T>  Result<T> fail(){
        return new Result<>(201,"fail",null);
    }

    public static<T>  Result<T> fail(Integer code){
        return new Result<>(code,"fail",null);
    }

    public static<T>  Result<T> fail(Integer code, String message){
        return new Result<>(code,message,null);
    }

    public static<T>  Result<T> fail( String message){
        return new Result<>(201,message,null);
    }
}
